1   /*
2    * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   */
23  
24  /* @test
25     @bug 4626545 4696726
26     @summary Checks the inter containment relationships between NIO charsets
27   */
28  
29  import java.nio.charset.*;
30  
31  public class CharsetContainmentTest {
32      static String[] encodings =
33          { "US-ASCII", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-8",
34            "windows-1252", "ISO-8859-1", "ISO-8859-15", "ISO-8859-2",
35            "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6",
36            "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-8859-13",
37            "ISO-2022-JP", "ISO-2022-KR",
38  
39            // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder
40            // support is added (4673614)
41            // "x-ISO-2022-CN-CNS", "x-ISO-2022-CN-GB",
42  
43            "x-ISCII91", "GBK", "GB18030", "Big5",
44            "x-EUC-TW", "GB2312", "EUC-KR", "x-Johab", "Big5-HKSCS",
45            "x-MS950-HKSCS", "windows-1251", "windows-1253", "windows-1254",
46            "windows-1255", "windows-1256", "windows-1257", "windows-1258",
47            "x-mswin-936", "x-windows-949", "x-windows-950", "windows-31j",
48            "Shift_JIS", "EUC-JP", "KOI8-R", "TIS-620"
49          };
50  
51      static String[][] contains = {
52          { "US-ASCII"},
53             encodings,
54             encodings,
55             encodings,
56             encodings,
57            {"US-ASCII", "windows-1252"},
58            {"US-ASCII", "ISO-8859-1"},
59            {"US-ASCII", "ISO-8859-15"},
60            {"US-ASCII", "ISO-8859-2"},
61            {"US-ASCII", "ISO-8859-3"},
62            {"US-ASCII", "ISO-8859-4"},
63            {"US-ASCII", "ISO-8859-5"},
64            {"US-ASCII", "ISO-8859-6"},
65            {"US-ASCII", "ISO-8859-7"},
66            {"US-ASCII", "ISO-8859-8"},
67            {"US-ASCII", "ISO-8859-9"},
68            {"US-ASCII", "ISO-8859-13"},
69            {"ISO-2022-JP"},
70            {"ISO-2022-KR"},
71            // Temporarily remove ISO-2022-CN-* charsets until full encoder/decoder
72            // support is added (4673614)
73            //{"x-ISO-2022-CN-CNS"},
74            //{"x-ISO-2022-CN-GB"},
75            {"US-ASCII", "x-ISCII91"},
76            {"US-ASCII", "GBK"},
77            encodings,
78            {"US-ASCII", "Big5"},
79            {"US-ASCII", "x-EUC-TW"},
80            {"US-ASCII", "GB2312"},
81            {"US-ASCII", "EUC-KR"},
82            {"US-ASCII", "x-Johab"},
83            {"US-ASCII", "Big5-HKSCS", "Big5"},
84            {"US-ASCII", "x-MS950-HKSCS", "x-windows-950"},
85            {"US-ASCII", "windows-1251"},
86            {"US-ASCII", "windows-1253"},
87            {"US-ASCII", "windows-1254"},
88            {"US-ASCII", "windows-1255"},
89            {"US-ASCII", "windows-1256"},
90            {"US-ASCII", "windows-1257"},
91            {"US-ASCII", "windows-1258"},
92            {"US-ASCII", "x-mswin-936"},
93            {"US-ASCII", "x-windows-949"},
94            {"US-ASCII", "x-windows-950"},
95            {"US-ASCII", "windows-31j" },
96            {"US-ASCII", "Shift_JIS"},
97            {"US-ASCII", "EUC-JP"},
98            {"US-ASCII", "KOI8-R"},
99            {"US-ASCII", "TIS-620"}};
100 
101 
102     public static void main(String[] args) throws Exception {
103         for (int i = 0; i < encodings.length; i++) {
104             Charset c = Charset.forName(encodings[i]);
105                 for (int j = 0 ; j < contains[i].length; j++) {
106                     if (c.contains(Charset.forName(contains[i][j])))
107                         continue;
108                     else {
109                         throw new Exception ("Error: charset " + encodings[i] +
110                                         "doesn't contain " + contains[i][j]);
111                     }
112                 }
113         }
114     }
115 }